<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('sms_codes', function (Blueprint $table) {
            $table->id();
            $table->string('key')->unique()->index()->comment('唯一标识');
            $table->string('guard')->index()->comment('守卫');
            $table->string('phone')->index()->comment('手机号');
            $table->string('code')->comment('短信验证码');
            $table->integer('attempts')->default(0)->comment('尝试次数');
            $table->boolean('is_used')->default(false)->comment('是否已使用');
            $table->timestamp('expired_at')->comment('过期时间');
            $table->timestamp('passed_at')->nullable()->comment('通过时间');
            $table->timestamps();
            $table->comment('短信验证码表');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('sms_codes');
    }
};
